<template>
  <div class="todo-container">
    <div class="todo-wrap">

      <!-- 头部 -->
      <Header :add-Todo="addTodo"></Header>  <!-- 这里将对应的方法函数作为传入对象传递到子组件中 -->

      <!-- 列表部分 -->
      <List :todos="todos" @del-todo="delTodoWithIndex"></List>

      <!-- 尾部 -->
      <Footer :todos="todos" 
              :selected-all-todo="selectedAllTodo" 
              :del-finished-todos="delFinishedTodos"></Footer>

    </div>
  </div>
</template>


<script>
import Header from './components/Header.vue';
import Footer from './components/Footer.vue';
import List from './components/List.vue';

export default {
  name: 'app',
  data() {
    return {
      todos: [
        {title: '打一场羽毛球', finished: false},
        {title: '打一场篮球', finished: false},
        {title: '打一场足球', finished: false},
        {title: '读一会书', finished: false},
      ],
    }
  },
  components: {
    Header,
    Footer,
    List
  },
  methods:{
    // 根据索引删除对应的 todo
    delTodoWithIndex(index){
      debugger
      this.todos.splice(index, 1);
    },
    // 添加 todo
    addTodo(todo){
      this.todos.unshift(todo);
    },
    // 全选或者取消全选
    selectedAllTodo(isChecked){
      this.todos.forEach( todo => {
        todo.finished = isChecked;
      });
    },
    // 删除已完成的 todo
    delFinishedTodos(){
      this.todos = this.todos.filter( todo => !todo.finished);
    },
  }
}
</script>

<style>
body {
  background-color: #fff;
}

.btn {
  display: inline-block;
  padding: 8px 10px;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}

.btn-warning {
  color: #fff;
  background-color: orange;
  border: none;
}

.btn-warning:hover {
  color: #fff;
  background-color: red;
}

.btn:focus {
  outline: none;
}

/*app*/
.todo-container {
  width: 600px;
  margin: 0 auto;
}

.todo-container .todo-wrap {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}
</style>
